package com.raycloud.query;

                                            import java.util.*;
/**
 *
 * @author lvduo (lvduo940613@gmail.com)
 */
public class EndProjectQuery extends BaseQuery {

	/**==============================批量查询、更新、删除时的Where条件设置==================================**/
	/** project_name **/
    private String projectName;
	public String getProjectName () {
    	return projectName;
   	}
    public EndProjectQuery setProjectName(String projectName) {
    	this.projectName = projectName;
    	return this;
    }
	/** project_path **/
    private String projectPath;
	public String getProjectPath () {
    	return projectPath;
   	}
    public EndProjectQuery setProjectPath(String projectPath) {
    	this.projectPath = projectPath;
    	return this;
    }
	/** tomcat_port **/
    private Integer tomcatPort;
	public Integer getTomcatPort () {
    	return tomcatPort;
   	}
    public EndProjectQuery setTomcatPort(Integer tomcatPort) {
    	this.tomcatPort = tomcatPort;
    	return this;
    }
	/** dubbo_port **/
    private Integer dubboPort;
	public Integer getDubboPort () {
    	return dubboPort;
   	}
    public EndProjectQuery setDubboPort(Integer dubboPort) {
    	this.dubboPort = dubboPort;
    	return this;
    }
	/** git_path **/
    private String gitPath;
	public String getGitPath () {
    	return gitPath;
   	}
    public EndProjectQuery setGitPath(String gitPath) {
    	this.gitPath = gitPath;
    	return this;
    }
	/** branch **/
    private String branch;
	public String getBranch () {
    	return branch;
   	}
    public EndProjectQuery setBranch(String branch) {
    	this.branch = branch;
    	return this;
    }
	/** profile **/
    private String profile;
	public String getProfile () {
    	return profile;
   	}
    public EndProjectQuery setProfile(String profile) {
    	this.profile = profile;
    	return this;
    }
	/** owner **/
    private String owner;
	public String getOwner () {
    	return owner;
   	}
    public EndProjectQuery setOwner(String owner) {
    	this.owner = owner;
    	return this;
    }
	/** status **/
    private String status;
	public String getStatus () {
    	return status;
   	}
    public EndProjectQuery setStatus(String status) {
    	this.status = status;
    	return this;
    }
	/** module_name **/
    private String moduleName;
	public String getModuleName () {
    	return moduleName;
   	}
    public EndProjectQuery setModuleName(String moduleName) {
    	this.moduleName = moduleName;
    	return this;
    }
	/** final_name **/
    private String finalName;
	public String getFinalName () {
    	return finalName;
   	}
    public EndProjectQuery setFinalName(String finalName) {
    	this.finalName = finalName;
    	return this;
    }
	/**==============================批量查询时的Order条件顺序设置==================================**/
	public class OrderField{
		public OrderField(String fieldName, String order) {
			super();
			this.fieldName = fieldName;
			this.order = order;
		}
		private String fieldName;
		private String order;
		public String getFieldName() {
			return fieldName;
		}
		public OrderField setFieldName(String fieldName) {
			this.fieldName = fieldName;
			return this;
		}
		public String getOrder() {
			return order;
		}
		public OrderField setOrder(String order) {
			this.order = order;
			return this;
		}
	}

	/**==============================批量查询时的Order条件顺序设置==================================**/
	/**排序列表字段**/
	private List<OrderField> orderFields = new ArrayList<OrderField>();
	/**
	 * 设置排序按属性：project_name
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyProjectName(boolean isAsc){
		orderFields.add(new OrderField("project_name",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：project_path
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyProjectPath(boolean isAsc){
		orderFields.add(new OrderField("project_path",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：tomcat_port
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyTomcatPort(boolean isAsc){
		orderFields.add(new OrderField("tomcat_port",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：dubbo_port
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyDubboPort(boolean isAsc){
		orderFields.add(new OrderField("dubbo_port",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：git_path
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyGitPath(boolean isAsc){
		orderFields.add(new OrderField("git_path",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：branch
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyBranch(boolean isAsc){
		orderFields.add(new OrderField("branch",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：profile
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyProfile(boolean isAsc){
		orderFields.add(new OrderField("profile",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：owner
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyOwner(boolean isAsc){
		orderFields.add(new OrderField("owner",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：status
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyStatus(boolean isAsc){
		orderFields.add(new OrderField("status",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：module_name
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyModuleName(boolean isAsc){
		orderFields.add(new OrderField("module_name",isAsc?"ASC":"DESC"));
		return this;
	}
	/**
	 * 设置排序按属性：final_name
	 * @param isAsc 是否升序，否则为降序
	 */	
	public EndProjectQuery orderbyFinalName(boolean isAsc){
		orderFields.add(new OrderField("final_name",isAsc?"ASC":"DESC"));
		return this;
	}
    private String fields;
    /**
     * 提供自定义字段使用
     */
    private static Map<String,String> fieldMap;

    private static Map<String,String> getFieldSet() {
        if (fieldMap == null){
            fieldMap =new HashMap<String,String>();
                    fieldMap.put("project_name", "projectName");
                    fieldMap.put("project_path", "projectPath");
                    fieldMap.put("tomcat_port", "tomcatPort");
                    fieldMap.put("dubbo_port", "dubboPort");
                    fieldMap.put("git_path", "gitPath");
                    fieldMap.put("branch", "branch");
                    fieldMap.put("profile", "profile");
                    fieldMap.put("owner", "owner");
                    fieldMap.put("status", "status");
                    fieldMap.put("module_name", "moduleName");
                    fieldMap.put("final_name", "finalName");
                }
        return fieldMap;
    }

    public String getFields(){
        return this.fields;
    }
    public EndProjectQuery  setFields(String fields){
        String[] array = fields.split(",");
        StringBuffer buffer = new StringBuffer();
        for (String field : array){
            if(getFieldSet().containsKey(field)){
                buffer.append(field).append(" as ").append(getFieldSet().get(field)).append(" ,");
            }
            if(getFieldSet().containsKey("`"+field+"`")){
                buffer.append("`"+field+"`").append(" as ").append(getFieldSet().get(field)).append(" ,");
            }
        }
        if (buffer.length() != 0){
            this.fields = buffer.substring(0, buffer.length() - 1);
        }else{
            this.fields = " 1 ";//没有一个参数可能会报错
        }
        return this;
    }
}
